package com.pd.backend.service.impl;

import com.pd.backend.enums.AppHttpCodeEnum;
import com.pd.backend.mapper.PdAreaMapper;
import com.pd.backend.pojo.PdArea;
import com.pd.backend.service.PdAreaService;
import com.pd.backend.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;

/**
 * 区域业务层实现
 */
@Service
@Transactional
@Slf4j
public class PdAreaServiceImpl implements PdAreaService {
    @Autowired
    private PdAreaMapper pdAreaMapper;
    @Override
    public ResponseResult<List<PdArea>> selectAreasByParentId(Integer parentId) {

        //校验参数
        if (Objects.isNull(parentId)){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //根据父id查询数据
        List<PdArea> pdAreas = pdAreaMapper.selectByParentId(parentId);
        return ResponseResult.okResult(pdAreas);
    }
}